import cn.yunhe.dao.ITopicDao;
import cn.yunhe.entity.Admin;
import cn.yunhe.entity.Topic;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


import java.util.List;

public class Demo {
    ApplicationContext ac = null;
    ITopicDao topicDao = null;

    @Before
    public void bef() {
        ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        topicDao = (ITopicDao) ac.getBean("topicDao");
    }

    @Test
    public void test1() {
        List<Topic> list = topicDao.searchAll();
        for (Topic t : list) {
            System.out.println(t.getTitle()+"  "+t.getAdmin().getA_name());
        }
    }

    @Test
    public void test2() {
        Topic topic = new Topic();
        topic.setTitle("springJDBC");
        int row = topicDao.save(topic);
        System.out.println(row);
    }
    @Test
    public void test3(){
        Topic topic=new Topic();
        //topic.setTid(16);
        topic.setTitle("springJDBC");
        /*Admin admin=new Admin();
        admin.setA_id(19);
        admin.setA_name("白狗");
        topic.setAdmin(admin);*/
        List<Topic> list=topicDao.searchByKey(topic);
        for (Topic t:list) {
            System.out.println(t);
        }
    }

}
